package com.jiangjiang.eshop.order.price.v1.factory;

import com.jiangjiang.eshop.order.dto.CouponDTO;
import com.jiangjiang.eshop.order.price.v1.calculator.CouponCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.impl.CashCouponCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.impl.DefaultCouponCalculator;
import com.jiangjiang.eshop.order.price.v1.calculator.impl.ReachDiscountCouponCalculator;
import com.jiangjiang.eshop.promotion.constant.CouponType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName CouponCalculatorFactory
 * @Description TODO
 * @Author jhw
 * @Date 2021/7/22 11:39
 * @Version 1.0
 **/
@Component
public class CouponCalculatorFactory {
    @Autowired
    private DefaultCouponCalculator defaultCouponCalculator;
    @Autowired
    private CashCouponCalculator cashCouponCalculator;
    @Autowired
    private ReachDiscountCouponCalculator reachDiscountCouponCalculator;

    public CouponCalculator create(CouponDTO couponDTO){
        if(CouponType.CASH_COUPON.equals(couponDTO.getType())){
            return cashCouponCalculator;
        } else if (CouponType.REACH_DISCOUNT_COUPON.equals(couponDTO.getType())){
            return reachDiscountCouponCalculator;
        }
        return defaultCouponCalculator;
    }
}
